from django.db import models
from rest_framework import serializers


class TwoAuthStatus(models.Model):
    """是否启用邮箱二次验证"""

    status = models.SmallIntegerField(verbose_name="邮箱二次认证(1启用，0禁用)", default=0)
    update_time = models.DateTimeField(null=True, verbose_name="更新时间", auto_now=True)

    class Meta:
        verbose_name = "邮箱二次验证状态表"
        db_table = "sys_two_auth_status"


# Create your models here.
class SysUser(models.Model):
    """用户表"""

    username = models.CharField(max_length=100, unique=True, verbose_name="用户名")
    password = models.CharField(max_length=100, verbose_name="密码")
    avatar = models.CharField(max_length=255, null=True, verbose_name="用户头像")
    email = models.CharField(max_length=100, null=True, verbose_name="用户邮箱")
    phone_number = models.CharField(max_length=16, null=True, verbose_name="手机号码")
    login_date = models.DateTimeField(null=True, verbose_name="最后登录时间")
    status = models.IntegerField(null=True, verbose_name="帐号状态（1正常 0停用）")
    create_time = models.DateTimeField(null=True, verbose_name="创建时间", auto_now_add=True)
    update_time = models.DateTimeField(null=True, verbose_name="更新时间", auto_now=True)
    remark = models.CharField(max_length=500, null=True, verbose_name="备注")

    class Meta:
        verbose_name = "用户表"
        db_table = "sys_user"


class SysUserSerializer(serializers.ModelSerializer):
    class Meta:
        model = SysUser
        fields = '__all__'


class SysLogs(models.Model):
    """系统日志表"""

    login_time = models.DateTimeField(null=True, verbose_name="登陆时间", auto_now_add=True)
    username = models.CharField(verbose_name="用户名", max_length=100)
    status = models.SmallIntegerField(verbose_name="登陆状态(1登陆成功，0登陆失败)")
    login_ip = models.GenericIPAddressField(verbose_name="登陆IP")
    user_agent = models.TextField(verbose_name="UserAgent", null=True)
    remark = models.TextField(verbose_name="备注", null=True)

    class Meta:
        verbose_name = "系统日志表"
        db_table = "sys_logs"


class SysLogsSerializer(serializers.ModelSerializer):
    class Meta:
        model = SysLogs
        fields = '__all__'
